<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工作流demo：请假申请列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>请假人id：</label>
                                <input type="text" name="userId"/>
                            </li>

                            <li>
                                <label>请假理由：</label>
                                <input type="text" name="reason"/>
                            </li>
                            <li>
                                <label>开始时间：</label>
                                <input type="text" class="time-input" placeholder="请选择开始时间" name="startTime"/>
                            </li>
                            <li>
                                <label>结束时间：</label>
                                <input type="text" class="time-input" placeholder="请选择结束时间" name="endTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:leave:add">
                    <i class="fa fa-plus"></i> 发起请假
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:leave:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="onClickApplicateLeave()" shiro:hasPermission="system:leave:remove">-->
<!--                    <i class="fa fa-remove"></i> 发起请假-->
<!--                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:leave:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:leave:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <!--请假脚本-->
     <script th:src="@{/js/leave.js}"></script>
     <script th:src="@{/js/common.js}"></script>

    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:leave:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:leave:remove')}]];
        var prefix = ctx + "system/leave";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "工作流demo：请假申请",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'userId',
                    title: '请假人id'
                },
                    {
                        field: 'userName',
                        title: '请假人'
                    },
                {
                    field: 'reason',
                    title: '请假理由'
                },
                {
                    field: 'startTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                    {
                        field: 'stateStr',
                        title: '状态'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" ' +
                            'href="javascript:void(0)" onclick="onclickcheck(\'' + row.id + '\')"><i class="fa fa-edit"></i>审批</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" ' +
                        //     'href="javascript:void(0)" onclick="onclickflow(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看流程</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" ' +
                            'href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function onclickflow(id)
        {
            console.log("点击流程="+id);
            $.modal.open("详细信息" , prefix+"/leaveindex/"+id, '1100', '900');
        }

        function onclickcheck(id)
        {
            layer.msg("点击审批操作id:"+id);


            //请求审批通过
            var data = {};
            data.id = id;
       //     data.userId = typeNum;//操作类型
            $.operate.save(  "/system/leave/complete", data);// $('#form-leave-add').serialize());
        }

        /**
        private Long id;
        @Excel(name = "请假人id")
        private Long userId;
        @Excel(name = "请假理由")
        private String reason;
        @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
        private Date startTime;
        @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
        private Date endTime;
         */

        //yanruTODO 发起请假
        // function onClickApplicateLeave() {
        //     layer.prompt({
        //         formType: 0,
        //         value: '',
        //         title: '请填写请假原因(请假1天)',
        //         btn: ['确定','取消'], //按钮，
        //         btnAlign: 'c'
        //     }, function(value,index){
        //         layer.close(index);
        //         //执行审批不通过的内容 此时获取到的数据为value
        //         console.log("输入的文本="+value);
        //         var data = {};
        //         data.userId = getCookie("userId");
        //         data.reason = value;
        //         data.startTime = new Date();
        //         data.endTime = new Date();
        //
        //     });
        // }
    </script>
</body>
</html>